<?php
/**
 * 此model不属于csv
 * Enter description here ...
 * @author Administrator
 *
 */
class CSVModel extends Db {
	
	//订单导入导出列表
	private $_order_csv = 'd_order_csv';
	
	public function getCSV($where) {
		return $this->getAll ( $this->_order_csv, $where );
	}
	
	public function getCSVGreaterThanId($id, $status = "all") {

		if ($status === "all") {
			$sql = "SELECT * FROM $this->_order_csv WHERE id>$id";
		} else {
			$sql = "SELECT * FROM $this->_order_csv WHERE id>$id AND `status`=$status";
		}
		return $this->fetchAll ( $sql );
	}
	
	/**
	 * 中奖用户
	 * @param int $round
	 */
	public function getPrize($round) {
		$sql = "select count(prize) prizenum,prize,sum(money) tmoney,jxs,uid,area,junqu from d_order_csv where round=$round group by jxs,prize order by junqu";
		return $this->fetchAll ( $sql );
	}
	
	public function dateLog($limit) {
		$sql = "select count(*) num,from_unixtime(add_time,\"%m-%d\") t,add_time from d_order_csv group by t ORDER BY add_time DESC LIMIT $limit";
		return $this->fetchAll ( $sql );
	}
	
	public function listing($start, $num, $where) {
		return $this->getPage ( $start, $num, $this->_order_csv, null, $where, 'id DESC' );
	}
	
	public function top() {
		$sql = "select count(id) num,a.uid,b.face from d_order_csv a left join w_member_list b ON a.uid=b.uid group by uid order by num desc ;";
		return $this->fetchAll ( $sql );
	}
	
	public function saveCSVStatus($v, $where) {
		return $this->update ( $this->_order_csv, $v, $where );
	}
	/**
	 * 前10明
	 * Enter description here ...
	 */
	public function topTen() {
		$sql = "SELECT count(id) num,junqu,jxs,a.area,b.face FROM d_order_csv a left join w_member_list b on a.uid=b.uid where jxs!='' group by jxs order by num desc  limit 10;";
		return $this->fetchAll ( $sql );
	}
	
	public function stat($status) {
		if ($status == null) {
			$sql = "select count(*) num,junqu from d_order_csv group by junqu";
		} else {
			$sql = "select count(*) num,junqu from d_order_csv where status=$status group by junqu";
		
		}
		return $this->fetchAll ( $sql );
	}
	
	public function statByMan($status) {
		if ($status == null) {
			$sql = "SELECT count(*) num,man FROM d_order_csv GROUP BY man ORDER BY num DESC";
		} else {
			$sql = "SELECT count(*) num,man FROM d_order_csv where status=$status GROUP BY man ORDER BY num DESC";
		
		}
		return $this->fetchAll ( $sql );
	}
	
	public function getMoney() {
		$sql = "select sum(money) money from d_order_csv where status IN (1,2)";
		return $this->fetch ( $sql );
	}
	
	/**
	 * 统计数量
	 * @param array $where
	 */
	public function countNum($where) {
		return $this->getNum ( $this->_order_csv, 'id', $where );
	}
	
	public function addOrder($param) {
		$this->add ( $this->_order_csv, $param );
	}
	
	public function remove($where) {
		return $this->delete ( $this->_order_csv, $where );
	}
	
	/**
	 * 
	 * @return  CSVModel
	 */
	public static function instance() {
		return self::_instance ( __CLASS__ );
	}

}